//
//  DSSHTaskMainVC.m
//  DSSH
//
//  Created by lcy on 16/3/28.
//  Copyright © 2016年 lcy. All rights reserved.
//
#define CUSBUTTONHIGHT 35
#define TOPHIGHT  ([UIApplication sharedApplication].statusBarFrame.size.height+self.navigationController.navigationBar.frame.size.height)

#import "DSSHTaskMainVC.h"
#import "CusNavButton.h"
#import "UIView+Ext.h"
#import "ProjectBtn.h"
#import "DSSHTaskRockVC.h"
#import "DSSHScanQRcode.h"
#import "UIView+Round.h"
#import "DSSHTaskNewsAndPublicVC.h"
#import "DSSHQiangTaskDetailVC.h"
#import "DSSHQiangTaskDetailOfDoingVC.h"
#import "DSSHQiangTaskDetailOfAddExplainVC.h"
#import "DSSHLingTaskDetailOfWaitForLingVC.h"
#import "DSSHLingTaskDetailWaitForJudge.h"
@interface DSSHTaskMainVC ()<UISearchBarDelegate,BMKMapViewDelegate,BMKLocationServiceDelegate>
{
    BMKMapView *_mapView;
    BMKLocationService *_locService;
    UIImageView * _Taskview;
    
}
@property(nonatomic,strong)UISearchBar *searchBar;
@property(nonatomic,strong)UIView *coverView;
@property(nonatomic,strong)UIView *newsView;
@property(nonatomic,strong)UIButton*lingBtn;

@end

@implementation DSSHTaskMainVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViewAndData];
    // Do any additional setup after loading the view.
    
}
#pragma 弹出新闻公告窗口
-(void)viewWillAppear:(BOOL)animated
{
    if (!self.newsView)
    {
        self.newsView = [[UIView alloc]init];
        self.newsView.frame = CGRectMake(0, 0, ZYAppWidth, 60*HIGHT_SCALE);
        self.newsView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:self.newsView];
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goToNewsDetail)];
        [self.newsView addGestureRecognizer:tap];
        
        UILabel * textLabel = [UILabel new];
        textLabel.center = self.newsView.center;
        textLabel.bounds = CGRectMake(0, 0, ZYAppWidth, 60*HIGHT_SCALE);
        textLabel.text = @"新闻公告";
        textLabel.font = FONT(17);
        textLabel.textAlignment = NSTextAlignmentCenter;
        [self.newsView addSubview:textLabel];
        
        UIButton * button = [UIButton new];
        [button setImage:[UIImage imageNamed:@"chahao"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(clickNewsBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.newsView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.newsView.mas_right).with.offset(-10*WIDTH_SCALE);
            make.top.equalTo(self.newsView.mas_top).with.offset(10*HIGHT_SCALE);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        [UIView animateWithDuration:0.5 animations:^{
            self.newsView.frame = CGRectMake(0, 64, ZYAppWidth, 60*HIGHT_SCALE);
        }];

    }
    
    
}
#pragma 点击移除新闻公告的view
-(void)clickNewsBtn
{
    [UIView animateWithDuration:0.5 animations:^{
        self.newsView.frame = CGRectMake(0, 0, ZYAppWidth, 60*HIGHT_SCALE);
    } completion:^(BOOL finished) {
        [self.newsView removeFromSuperview];
        self.newsView = nil;
    }];
}
-(void)goToNewsDetail
{
    DSSHTaskNewsAndPublicVC * newsVC = [[DSSHTaskNewsAndPublicVC alloc]init];
    [self.navigationController pushViewController:newsVC animated:YES];
}
-(void)setupViewAndData
{
    [self setNavigationView];
    
    //添加地图部分
    _mapView = [[BMKMapView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:_mapView];
    _mapView.delegate = self;
    _mapView.showsUserLocation = YES;
    _locService = [[BMKLocationService alloc]init];
    _locService.delegate = self;
    [_locService startUserLocationService];
    //添加大头针
    BMKPointAnnotation* annotation1 = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor1;
    coor1.latitude = 39.905;
    coor1.longitude = 116.404;
    annotation1.coordinate = coor1;
    annotation1.title = @"这里是北京";
    annotation1.subtitle = @"1";
    [_mapView addAnnotation:annotation1];
    
    BMKPointAnnotation* annotation2 = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor2;
    coor2.latitude = 39.965;
    coor2.longitude = 116.404;
    annotation2.coordinate = coor1;
    annotation2.title = @"这里是北京";
    annotation2.subtitle = @"2";
    [_mapView addAnnotation:annotation2];
    
    BMKPointAnnotation* annotation3 = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor3;
    coor3.latitude = 39.905;
    coor3.longitude = 116.654;
    annotation3.coordinate = coor3;
    annotation3.title = @"这里是北京";
    annotation3.subtitle = @"3";
    [_mapView addAnnotation:annotation3];
}
-(void)setNavigationView
{
    UIView * barView = [UIView new];
    barView.frame = CGRectMake(0, 0, ZYAppWidth, 64);
    self.navigationItem.titleView = barView;
    [barView addSubview:[self createview]];
    
    ProjectBtn * settingBtn = [ProjectBtn new];
    settingBtn.frame = CGRectMake(8*WIDTH_SCALE, 18, 20*WIDTH_SCALE, 32);
    settingBtn.LabelTitle.text = @"设置";
    settingBtn.LabelTitle.font = FONT(8);
    settingBtn.image.image = [UIImage imageNamed:@"list"];
//    [settingBtn addTarget:self action:@selector(saoBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [barView addSubview:settingBtn];
    
    ProjectBtn * locationBtn = [ProjectBtn new];
    locationBtn.frame = CGRectMake(ZYAppWidth-(20+20+40)*WIDTH_SCALE, 18, 20*WIDTH_SCALE, 32);
    locationBtn.LabelTitle.text = @"定位";
    locationBtn.LabelTitle.font = FONT(8);
    
    locationBtn.image.image = [UIImage imageNamed:@"coordinate"];
    [locationBtn addTarget:self action:@selector(locationBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [barView addSubview:locationBtn];
    
    ProjectBtn * taskBtn = [ProjectBtn new];
    taskBtn.frame = CGRectMake(ZYAppWidth-(20+20)*WIDTH_SCALE, 18, 20*WIDTH_SCALE, 32);
    taskBtn.LabelTitle.text = @"任务";
    taskBtn.LabelTitle.font = FONT(8);
    
    taskBtn.image.image = [UIImage imageNamed:@"dakaizhuangtai"];
    [taskBtn addTarget:self action:@selector(taskBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [barView addSubview:taskBtn];
}
-(UIView *)createview
{
    
    UIView *Mview = [[UIView alloc] initWithFrame:CGRectMake(50*WIDTH_SCALE, 15, ZYAppWidth-50*WIDTH_SCALE-90*WIDTH_SCALE, 30)];
    Mview.backgroundColor = [UIColor whiteColor];
    Mview.layer.cornerRadius = 5;
    
    UIImageView *imageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"fangdajing"]];
    [Mview addSubview:imageview];
    [imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(@20);
        make.centerY.equalTo(Mview.mas_centerY);
        make.left.equalTo(Mview.mas_left).with.offset(5);
    }];
    UIButton *secarchbutton = [[UIButton alloc] init];
    [secarchbutton addTarget:self action:@selector(saoyisao) forControlEvents:UIControlEventTouchUpInside];
    [Mview addSubview:secarchbutton];
    [secarchbutton setBackgroundImage:[UIImage imageNamed:@"saoyisao"] forState:UIControlStateNormal];
    [secarchbutton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@20);
        make.centerY.equalTo(Mview.mas_centerY);
        make.width.equalTo(@20);
        make.right.equalTo(Mview.mas_right).with.offset(-5);
    }];
    
    UITextField *textfield = [[UITextField alloc] init];
    [Mview addSubview:textfield];
    textfield.font = [UIFont systemFontOfSize:13.0];
    textfield.placeholder = @"搜索相关内容";
    [textfield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageview.mas_right).with.offset(0);
        make.centerY.equalTo(Mview.mas_centerY);
        make.height.equalTo(@30);
        make.right.equalTo(secarchbutton.mas_left).with.offset(0);
        
    }];
    
    
    
    return Mview;
    
}

#pragma 点击扫一扫
-(void)saoyisao
{
    DSSHScanQRcode * scanVC = [[DSSHScanQRcode alloc]init];
    scanVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:scanVC animated:YES];
}
#pragma 点击定位
-(void)locationBtnClick
{
    DSSHTaskRockVC * rockVC = [[DSSHTaskRockVC alloc]init];
    [self.navigationController pushViewController:rockVC animated:YES];
}
#pragma 点击任务
-(void)taskBtnClick
{
    //    [self createSeleteview];
    CGFloat Thight = self.view.frame.size.height *0.7;
    CGFloat Twigth = self.view.frame.size.width *0.5;
    CGFloat Tx     = self.view.frame.size.width *0.5+5;
    CGFloat Ty     = 60;
    static int count = 0;
    count++;
    if (count%2==0)
    {
        //移除
        [UIView animateWithDuration:0.3 animations:^{
            _Taskview.frame = CGRectMake(Tx, Ty , Twigth,0);
        } completion:^(BOOL finished) {
            [_Taskview removeFromSuperview];
            [self.coverView removeFromSuperview];
            //            _Taskview = nil;
        }];
    }else
    {
        //展开
        UIView *coverView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        [self.view addSubview:coverView];
        self.coverView = coverView;
        UIImage *image = [UIImage imageNamed:@"renwukuang"];
        
        image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0,image.size.width-30,0,30) resizingMode:UIImageResizingModeStretch];
        _Taskview = [[UIImageView alloc] initWithFrame:CGRectMake(Tx, Ty , Twigth,0)];
        [_Taskview setImage:image];
        _Taskview.userInteractionEnabled = YES;
        
        //要改。。。。
        [[UIApplication sharedApplication].keyWindow addSubview:_Taskview];
        [UIView animateWithDuration:0.5 animations:^{
            _Taskview.frame = CGRectMake(Tx, Ty , Twigth, Thight);
        } completion:^(BOOL finished) {
            UIButton *buttonDown = [[UIButton alloc] init];
            buttonDown.backgroundColor = COLOR_NAVIGATE_BAR;
            [buttonDown setTitle:@"任务类型" forState:UIControlStateNormal];
            CGSize titleSize = [buttonDown.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:FONT(14)}];
            
            buttonDown.titleLabel.textAlignment = NSTextAlignmentLeft;
            buttonDown.tintColor = [UIColor whiteColor];
            buttonDown.titleEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);
            buttonDown.imageEdgeInsets = UIEdgeInsetsMake(0, titleSize.width+35, 0, -titleSize.width-35);
            //            _taskbutton = buttonDown;
            [buttonDown addTarget:self action:@selector(downlistbutton) forControlEvents:UIControlEventTouchUpInside];
            [buttonDown setImage:[UIImage imageNamed:@"xiala"] forState:UIControlStateNormal];
            [_Taskview addSubview:buttonDown];
            buttonDown.titleLabel.font = [UIFont systemFontOfSize:14.0];
            [buttonDown mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_Taskview.mas_top ).with.offset(14);
                make.centerX.equalTo(_Taskview.mas_centerX);
                make.width.mas_equalTo(_Taskview.frame.size.width -30);
                make.height.mas_equalTo(30);
            }];
            NSArray * imageArray = [[NSArray alloc]initWithObjects:@"xiangmugaikuang1",@"dengdaihuifu",@"lingqu",@"kaishishiyong", nil];
            NSArray * titleArray = [[NSArray alloc]initWithObjects:@"全部",@"待确认",@"待领取",@"执行中", nil];
            for (int i = 0; i<4; i++)
            {
                UIButton * btn = [[UIButton alloc]init];
                btn.titleEdgeInsets = UIEdgeInsetsMake(0, -34*WIDTH_SCALE, -34*WIDTH_SCALE, 0);
                btn.imageEdgeInsets = UIEdgeInsetsMake(-26*HIGHT_SCALE, 0, 0, -34*WIDTH_SCALE);
                [btn setTitle:titleArray[i] forState:UIControlStateNormal];
                [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
                btn.frame = CGRectMake(Twigth/2-40/2*WIDTH_SCALE, 70*HIGHT_SCALE+(60+20)*i*HIGHT_SCALE, 40*WIDTH_SCALE, 60*HIGHT_SCALE);
                [btn setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
                btn.titleLabel.textAlignment = NSTextAlignmentRight;
                btn.titleLabel.font = FONT(12);
                [_Taskview addSubview:btn];
            }
            
            UIButton *searchBtn = [UIButton new];
            [searchBtn setTitle:@"高级搜索" forState:UIControlStateNormal];
            searchBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
            searchBtn.titleLabel.font = FONT(13);
            [searchBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];;
            [searchBtn setImage:[UIImage imageNamed:@"fangdajing"] forState:UIControlStateNormal];
            [searchBtn setBackgroundColor:RGBA(252, 222, 224, 1)];
            [_Taskview addSubview:searchBtn];
            searchBtn.frame = CGRectMake(0, Thight-40, Twigth, 30);
            //            [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            //                make.bottom.equalTo(_Taskview.mas_bottom ).with.offset(-10*HIGHT_SCALE);
            //                make.left.equalTo(_Taskview.mas_left).with.offset(0);
            //                make.width.mas_equalTo(Twigth);
            //                make.height.mas_equalTo(30*HIGHT_SCALE);
            //            }];
            UIButton *sendBtn = [UIButton new];
            [sendBtn setTitle:@"发布任务" forState:UIControlStateNormal];
            sendBtn.titleLabel.font = FONT(13);
            [sendBtn getRoundView:5];
            [sendBtn setBackgroundColor:RGBA(242, 80, 87, 1)];
            [_Taskview addSubview:sendBtn];
            [sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(searchBtn.mas_top ).with.offset(-15*HIGHT_SCALE);
                make.centerX.equalTo(_Taskview.mas_centerX);
                make.width.mas_equalTo(90*WIDTH_SCALE);
                make.height.mas_equalTo(30*HIGHT_SCALE);
            }];
        }];
        
    }
}
#pragma 点击任务类型按钮
-(void)downlistbutton
{
    
}
#pragma BMKLocationSearveDelegate
-(void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    _mapView.showsUserLocation = YES;
    [_mapView updateLocationData:userLocation];
    [_mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
    //    [_locService stopUserLocationService];
}
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        
        
        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
        
        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
        
        newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
        
        newAnnotationView.annotation=annotation;
        
        if ([newAnnotationView.annotation.subtitle isEqualToString:@"1"])
        {
            newAnnotationView.image = [UIImage imageNamed:@"1"];   //把大头针换成别的图片
            
        }
        if ([newAnnotationView.annotation.subtitle isEqualToString:@"2"])
        {
            newAnnotationView.image = [UIImage imageNamed:@"2.png"];   //把大头针换成别的图片
            UIView * paoView = [self customPaoPaoView:@"qiang"];
            newAnnotationView.paopaoView = [[BMKActionPaopaoView alloc]initWithCustomView:paoView];
        }
        if ([newAnnotationView.annotation.subtitle isEqualToString:@"3"])
        {
            newAnnotationView.image = [UIImage imageNamed:@"3.png"];   //把大头针换成别的图片
            UIView * paoView = [self customPaoPaoView:@"ling"];
            newAnnotationView.paopaoView = [[BMKActionPaopaoView alloc]initWithCustomView:paoView];
        }
        
        return newAnnotationView;
    }
    return nil;
}
#pragma 自定义弹出气泡视图
-(UIView*)customPaoPaoView:(NSString*)titleStr
{
    UIView * customView = [[UIView alloc]init];
    customView.frame = CGRectMake(0, 0, 160, 220);
    UIImageView * imageView = [[UIImageView alloc]init];
    imageView.frame  = customView.frame;
    UIImage* paoImage = [UIImage imageNamed:@"tuanhuakuang"];
    UIImage* newImage = [paoImage stretchableImageWithLeftCapWidth:15 topCapHeight:12];
    imageView.image = newImage;
    [customView addSubview:imageView];
    
    UILabel * titleLabel = [UILabel new];
    
    
    titleLabel.font = FONT(13);
    titleLabel.textColor = [UIColor redColor];
    [customView addSubview:titleLabel];
    
    UILabel * nameLabel = [UILabel new];
    nameLabel.text = @"名称：相依画舫";
    nameLabel.font = FONT(12);
    [customView addSubview:nameLabel];
    
    UILabel * addrLabel = [UILabel new];
    addrLabel.text = @"地址：未来之光";
    addrLabel.font = FONT(12);
    [customView addSubview:addrLabel];
    
    UILabel * typeLabel = [UILabel new];
    typeLabel.text = @"类型：上画";
    typeLabel.font = FONT(12);
    [customView addSubview:typeLabel];
    
    UILabel * peopleLabel = [UILabel new];
    peopleLabel.text = @"发单人：张三";
    peopleLabel.font = FONT(12);
    [customView addSubview:peopleLabel];
    
    UILabel *percentageLabel = [UILabel new];
    percentageLabel.text = @"97%";
    percentageLabel.font = FONT(10);
    
    [customView addSubview:percentageLabel];
    
    UILabel * sendTimeLabel = [UILabel new];
    sendTimeLabel.text = @"发单时间：16.03.03";
    sendTimeLabel.font = FONT(12);
    [customView addSubview:sendTimeLabel];

    UILabel * endTimeLabel = [UILabel new];
    endTimeLabel.text = @"结束时间：16.03.05";
    endTimeLabel.font = FONT(12);
    [customView addSubview:endTimeLabel];
    
    UILabel * countDownLabel = [UILabel new];
    countDownLabel.text = @"倒计时：20分钟";
    countDownLabel.font = FONT(12);
    [customView addSubview:countDownLabel];

    UILabel * distanceLabel = [UILabel new];
    distanceLabel.text = @"距离：15公里";
    distanceLabel.font = FONT(12);
    [customView addSubview:distanceLabel];
    
    UILabel * mediumNumLabel = [UILabel new];
    mediumNumLabel.font = FONT(12);
    mediumNumLabel.textAlignment = NSTextAlignmentCenter;
    mediumNumLabel.text = @"11";
    [customView addSubview:mediumNumLabel];
    UILabel * mediumLabel = [UILabel new];
    
    mediumLabel.font = FONT(12);
    mediumLabel.textAlignment = NSTextAlignmentCenter;
    mediumLabel.text = @"媒体";
    [customView addSubview:mediumLabel];
    
    UILabel * relatedNumLabel = [UILabel new];
    relatedNumLabel.textColor = [UIColor redColor];
    relatedNumLabel.font = FONT(12);
    relatedNumLabel.textAlignment = NSTextAlignmentCenter;
    relatedNumLabel.text = @"8";
    [customView addSubview:relatedNumLabel];
    
    UILabel * relatedLabel = [UILabel new];
    relatedLabel.textColor = [UIColor redColor];
    relatedLabel.font = FONT(12);
    relatedLabel.textAlignment = NSTextAlignmentCenter;
    relatedLabel.text = @"关联任务";
    relatedLabel.numberOfLines = 0;
    [customView addSubview:relatedLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(customView.mas_centerX);
        make.height.mas_equalTo(20);
        make.top.equalTo(customView.mas_top).with.offset(10);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(40);
        make.right.equalTo(customView.mas_right).with.offset(0);
        make.height.mas_equalTo(20);
        make.top.equalTo(titleLabel.mas_bottom).with.offset(8);
    }];
    [addrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(40);
        make.right.equalTo(customView.mas_right).with.offset(0);
        make.height.mas_equalTo(20);
        make.top.equalTo(nameLabel.mas_bottom).with.offset(0);
    }];
    [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(40);
        make.right.equalTo(customView.mas_right).with.offset(0);
        make.height.mas_equalTo(20);
        make.top.equalTo(addrLabel.mas_bottom).with.offset(0);
    }];
    [peopleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(40);
        make.right.equalTo(customView.mas_right).with.offset(0);
        make.height.mas_equalTo(20);
        make.top.equalTo(typeLabel.mas_bottom).with.offset(0);
    }];
    [percentageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(customView.mas_left).with.offset(40*WIDTH_SCALE);
        make.right.equalTo(customView.mas_right).with.offset(0);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(30);
        make.bottom.equalTo(peopleLabel.mas_bottom).with.offset(0);
    }];
    [sendTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(40);
        make.right.equalTo(customView.mas_right).with.offset(0);
        make.height.mas_equalTo(20);
        make.top.equalTo(peopleLabel.mas_bottom).with.offset(0);
    }];
    [endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(40);
        make.right.equalTo(customView.mas_right).with.offset(0);
        make.height.mas_equalTo(20);
        make.top.equalTo(sendTimeLabel.mas_bottom).with.offset(0);
    }];
    [countDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(40);
        make.right.equalTo(customView.mas_right).with.offset(0);
        make.height.mas_equalTo(20);
        make.top.equalTo(endTimeLabel.mas_bottom).with.offset(0);
    }];
    [distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(40);
        make.right.equalTo(customView.mas_right).with.offset(0);
        make.height.mas_equalTo(20);
        make.top.equalTo(countDownLabel.mas_bottom).with.offset(0);
    }];
    [mediumNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(5);
        make.right.equalTo(nameLabel.mas_left).with.offset(-10);
        make.height.mas_equalTo(20);
        make.top.equalTo(titleLabel.mas_bottom).with.offset(8*HIGHT_SCALE);
    }];
    [mediumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(5);
        make.right.equalTo(nameLabel.mas_left).with.offset(-10);
        make.height.mas_equalTo(20);
        make.top.equalTo(mediumNumLabel.mas_bottom).with.offset(0);
    }];
    [relatedNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(5);
        make.right.equalTo(peopleLabel.mas_left).with.offset(-10);
        make.height.mas_equalTo(20);
        make.top.equalTo(typeLabel.mas_bottom).with.offset(0);
    }];
    [relatedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(customView.mas_left).with.offset(5);
        make.right.equalTo(peopleLabel.mas_left).with.offset(-10);
//        make.height.mas_equalTo(20*HIGHT_SCALE);
        make.top.equalTo(relatedNumLabel.mas_bottom).with.offset(0);
    }];
    
    if ([titleStr isEqualToString:@"ling"])
    {
        titleLabel.text = @"待领取";
        percentageLabel.textColor = RGBA(76, 120, 202, 1);
        mediumNumLabel.textColor = RGBA(76, 120, 202, 1);
        mediumLabel.textColor = RGBA(76, 120, 202, 1);
        
    }else
    {
        titleLabel.text = @"待抢单";
        percentageLabel.textColor = RGBA(74, 141, 73, 1);
        mediumNumLabel.textColor = RGBA(74, 141, 73, 1);
        mediumLabel.textColor = RGBA(74, 141, 73, 1);
        
        UILabel * qiangNumLabel = [UILabel new];
        qiangNumLabel.textColor = RGBA(74, 141, 73, 1);
        qiangNumLabel.font = FONT(12);
        qiangNumLabel.textAlignment = NSTextAlignmentCenter;
        qiangNumLabel.text = @"16";
        [customView addSubview:qiangNumLabel];
        
        UILabel * qiangLabel = [UILabel new];
        qiangLabel.textColor = RGBA(74, 141, 73, 1);
        qiangLabel.font = FONT(12);
        qiangLabel.textAlignment = NSTextAlignmentCenter;
        qiangLabel.text = @"抢单任务";
        qiangLabel.numberOfLines = 0;
        [customView addSubview:qiangLabel];
        
        [qiangNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(customView.mas_left).with.offset(5);
            make.right.equalTo(peopleLabel.mas_left).with.offset(-10);
            make.height.mas_equalTo(15);
            make.top.equalTo(relatedLabel.mas_bottom).with.offset(12*HIGHT_SCALE);
        }];

        [qiangLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(customView.mas_left).with.offset(5);
            make.right.equalTo(distanceLabel.mas_left).with.offset(-10);
//            make.height.mas_equalTo(30*HIGHT_SCALE);
            make.top.equalTo(qiangNumLabel.mas_bottom).with.offset(0);
        }];
        
        
    }

    return customView;
}
//点击大头针的操作
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
{
    if (!self.lingBtn)
    {
        self.lingBtn = [UIButton new];
        [self.view addSubview:self.lingBtn];
    }
    
    self.lingBtn.frame = CGRectMake((ZYAppWidth-69*WIDTH_SCALE)/2, ZYAppHeight, 69*WIDTH_SCALE, 36*HIGHT_SCALE);
    if ([view.annotation.subtitle isEqualToString:@"3"])
    {
        //领
        [self.lingBtn setBackgroundImage:[UIImage imageNamed:@"taskLing"] forState:UIControlStateNormal];
        self.lingBtn.tag = 1;
    }else
    {
        //抢
        [self.lingBtn setBackgroundImage:[UIImage imageNamed:@"taskQiang"] forState:UIControlStateNormal];
        self.lingBtn.tag = 2;
    }
    
    [self.lingBtn addTarget:self action:@selector(clickLingBtn:) forControlEvents:UIControlEventTouchUpInside];
   
    [UIView animateWithDuration:0.3 animations:^{
        self.lingBtn.frame = CGRectMake((ZYAppWidth-69*WIDTH_SCALE)/2, ZYAppHeight-49-36*HIGHT_SCALE, 69*WIDTH_SCALE, 36*HIGHT_SCALE);
    }];
}
#pragma 点击下面的领字
-(void)clickLingBtn:(UIButton*)btn
{
//    DSSHQiangTaskDetailVC *detailVC = [[DSSHQiangTaskDetailVC alloc]init];
//    [self.navigationController pushViewController:detailVC animated:YES];
    if (btn.tag == 2)
    {
        DSSHQiangTaskDetailOfAddExplainVC *detailVC = [[DSSHQiangTaskDetailOfAddExplainVC alloc]init];
        detailVC.type = 0;
        [self.navigationController pushViewController:detailVC animated:YES];
    }else
    {
//        DSSHLingTaskDetailOfWaitForLingVC *detailVC = [[DSSHLingTaskDetailOfWaitForLingVC alloc]init];
//        [self.navigationController pushViewController:detailVC animated:YES];
        DSSHLingTaskDetailWaitForJudge *detailVC = [[DSSHLingTaskDetailWaitForJudge alloc]init];
        detailVC.type = 2;
        [self.navigationController pushViewController:detailVC animated:YES];
    }
    
//    DSSHQiangTaskDetailOfDoingVC *detailVC = [[DSSHQiangTaskDetailOfDoingVC alloc]init];
//    detailVC.type = 1;
//    [self.navigationController pushViewController:detailVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
